package com.devunion.bogdan.persistence;

import java.io.Serializable;

import java.util.List;


/**
 * Base interface to be implemented by DAO interfaces.
 *
 * @author Viktar Liaskovich
 */
public interface Dao<E> {
    /**
     * Load object by primary key.
     *
     * @param key primary key
     *
     * @return object with given key or <code>null</code> if it can not be found.
     */
    E getByKey(Serializable key);

/**
     * Return list of all objects in underlying data source.
     *
     * @return list of all objects in underlying data source
     */
    List<E> loadAll();

    /**
     * Saves or updates (necessary operation is determined automatically, see
     * hibernate documentation for more details).
     *
     * @param obj object to save/update
     */
    void saveOrUpdate(E obj);

    /**
     * Saves object.
     *
     * @param obj object to save.
     */
    void save(E obj);

    /**
     * Updates object.
     *
     * @param obj object to update.
     */
    void update(E obj);

    /**
     * Delete given object.
     *
     * @param obj object to delete.
     */
    void delete(E obj);

    /**
     * Refresh given object.
     *
     * @param obj object that need to be refreshed.
     */
    void refresh(E obj);
}
